//
//  AdEmptyViewController.swift
//  Automobile
//
//  Created by erkebulan elzhan on 7/27/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit
import SnapKit

protocol AdEmptyViewDelegate {
    func onCreateAdClick ()
}

final class AdEmptyView: UIView {
    
    // MARK: - Outlets
    
    lazy private var emptyImage: UIImageView = {
        let image = UIImageView()
        image.contentMode = .scaleAspectFit
        image.image = UIImage(named: "emptyBox")
        return image
    }()
    
    lazy private var titleLbl: UILabel = {
        let lbl = UILabel()
        lbl.font = UIFont.systemFont(ofSize: 20, weight: .bold)
        lbl.textColor = .mediumDarkBlue
        lbl.textAlignment = .left
        lbl.text = "Продать - легко!"
        return lbl
    }()
    
    lazy private var detailsLbl: UILabel = {
        let lbl = UILabel()
        lbl.numberOfLines = 0
        lbl.font = UIFont.systemFont(ofSize: 15, weight: .regular)
        lbl.textAlignment = .left
        lbl.sizeToFit()
        lbl.textColor = .greyColor
        lbl.text = "Добавьте объявление, и его увидят тысячи потенциальных покупателей. Войдите, чтобы получить доступ к своим объявлениям"
        return lbl
    }()
    
    lazy private var submitBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("Добавить объявление", for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel!.font = UIFont.systemFont(ofSize: 17, weight: .medium)
        btn.backgroundColor = .blueColor
        btn.layer.cornerRadius = 15
        return btn
    }()
    
    // MARK: - Properties
    
    var delegate: AdEmptyViewDelegate!
    
    // MARK: - UI Actions
    
    @objc private func onAddAdClick (sender: UIButton) {
        delegate.onCreateAdClick()
    }
    
    // MARK: - Init
    
    init () {
        super.init(frame: .zero)
        self.addViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    
    private func addViews () {
        self.addSubview(emptyImage)
        self.addSubview(titleLbl)
        self.addSubview(detailsLbl)
        self.addSubview(submitBtn)
        self.addUIConstraints()
        
        submitBtn.addTarget(self, action: #selector(onAddAdClick(sender:)), for: .touchUpInside)
    }
    
    private func addUIConstraints () {
        submitBtn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().inset(23)
            make.leading.trailing.equalToSuperview().inset(16)
            make.height.equalTo(44)
        }
        detailsLbl.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview().inset(16)
            make.bottom.equalTo(submitBtn.snp.top).offset(-35)
            make.height.equalTo(63)
        }
        titleLbl.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview().inset(16)
            make.bottom.equalTo(detailsLbl.snp.top).offset(-18)
            make.height.equalTo(24)
        }
        emptyImage.snp.makeConstraints { (make) in
            make.bottom.equalTo(titleLbl.snp.top).offset(-38)
            make.width.centerX.equalToSuperview()
            make.top.equalToSuperview().inset(21)
        }
    }
}
